<template>
	<view class="container">
		<view class="info-box">
			<view class="info">
				<view class="user">
					<view class="info-img">
						<image class="img" src="/static/img/1.png" />
					</view>
					<view class="info-content">
						<view class="name">{{userInfo.RealName}}</view>
						<view class="mobile">{{userInfo.PhoneShow}}</view>
					</view>
				</view>
				<view class="menu">
					<view class="item" @tap="tapItem" data-index="1">
						<view class="item-label">孩子信息</view>
						<view class="item-more">+</view>
					</view>
					<view class="divider"></view>
					<view class="item" @tap="tapItem" data-index="2">
						<view class="item-label">问题反馈</view>
						<view class="item-more">+</view>
					</view>
					<view class="divider"></view>
					<view class="item" @tap="tapItem" data-index="3">
						<view class="item-label">联系我们</view>
						<view class="item-more">+</view>
					</view>
					<view class="divider"></view>
					<view class="item" @tap="tapItem" data-index="4">
						<view class="item-label">签约支付</view>
						<view class="item-more">+</view>
					</view>
					<view class="divider"></view>
					<view class="item" @tap="tapItem" data-index="5">
						<view class="item-label">切换老师身份</view>
						<view class="item-not-tap">非老师身份请勿点击</view>
					</view>
					<view class="divider"></view>
				</view>
			</view>
		</view>
		
		<mytabbar :currentId="currentId"></mytabbar>
		<myhome :show-my-home="showMyHome" :family-member-num="familyMemberNum" :children-member-num="childrenMemberNum"></myhome>
		
		<view class="feedback-bg" v-show="isShowFeedback" @tap="hideFeedback">
			<view class="feedback-container" @tap.stop="">
				<view class="feedback-input-box">
					<textarea class="feedback-input" placeholder="请输入反馈内容" v-model="feedbackContent"></textarea>
				</view>
				<view class="feedback-submit" @tap="feedback">提交</view>
			</view>
		</view>
		
		<view class="contact-bg" v-show="isShowContact" @tap="hideContact">
			<view class="contact-container" @tap.stop="callPhone">
				<view class="contact-phone">{{phoneNum}}</view>
				<view class="contact-phone-img"></view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import mytabbar from "../../components/mytabbar.vue"
	import myhome from "../../components/myhome.vue"
	import {myRequest,showToastMsg} from '../../utils'

	export default {
		components: {
			mytabbar,
			myhome
		},
		
		data() {
			return {
				loading: false,
				isShowFeedback: false,
				isShowContact: false,
				showMyHome: false,
				currentId: '3',
				userInfo: {RealName: '', PhoneShow: ''},
				familyMemberNum: 0,
				childrenMemberNum: 0,
				feedbackContent: '',
				timer: null,
				phoneNum: '18538525777'
			}
		},
	
		onShow() {
			
			let that = this
			
			myRequest({
				url: '/api/user/check_login',
				data: {},
			}, function(res) {
				
				if (res.statusCode != 200) {
					uni.showModal({
						title: '提示',
						content: '服务器错误，请求失败'
					})
					return
				}
				
				if (res.data.status != 0) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				
				that.familyMemberNum = res.data.data.FamilyMemberNum
				that.childrenMemberNum = res.data.data.ChildrenMemberNum
				that.userInfo = res.data.data
				
			})
			
		},
		
		methods: {
			
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: this.phoneNum
				})
			},
			
			showHome() {
				this.showMyHome = true
			},
			
			closeHome() {
				this.showMyHome = false
			},
			
			showContact() {
				this.isShowContact = true
			},
			
			hideContact() {
				this.isShowContact = false
			},
			
			showFeedback() {
				this.isShowFeedback = true
			},
			
			hideFeedback() {
				this.isShowFeedback = false
			},
			
			tapItem(e) {
				let index = e.currentTarget.dataset.index
				switch (index) {
					case '1':
						uni.navigateTo({
							url: '/pages/protect_member/protect_member'
						})
						break
					case '2':
						this.showFeedback()
						break
					case '3':
						console.log('ok')
						this.showContact()
						break
					case '4':
						showToastMsg('正在开发，敬请期待...')
						break
					case '5':
						uni.navigateTo({
							url: '/pages/teacher_index/teacher_index'
						})
						break
					default:
						break
				}
			},
			
			feedback() {
				
				let that = this
				
				if (that.feedbackContent.trim().length <= 0) {
					showToastMsg('请输入反馈内容')
					return
				}
				
				if (that.loading) return
				that.loading = true
				
				uni.showLoading({
					title: '拼命提交中...',
					success() {
						
						if (that.timer != null) {
							clearTimeout(that.timer)
						}
						
						that.timer = setTimeout(function() {
							
							myRequest({
								url: '/api/user/feedback',
								data: {
									content: that.feedbackContent
								},
							}, function(res) {
								
								uni.hideLoading()
								
								if (res.statusCode != 200) {
									uni.showModal({
										title: '提示',
										content: '服务器错误，请求失败'
									})
									return
								}
								
								if (res.data.status == 1000) {
									uni.navigateTo({
										url: '/pages/login/login'
									})
									return
								}
								
								showToastMsg(res.data.msg)
								
								if (res.data.status == 0) {
									that.feedbackContent = ''
									that.hideFeedback()
								}
								
							})
							
						}, 1000)
						
					}
				})
				
			}
			
		}
	}
</script>

<style>
	.container {
		width: 750rpx;
		height: auto;
		background-image: linear-gradient(#ffae00, #eee, #efefef);
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 160rpx;
	}

	.info-box {
		width: 86%;
		height: 1200rpx;
		background-color: #ffffff;
		margin-top: 30rpx;
		border-radius: 20rpx 20rpx 0 0;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.info {
		display: flex;
		flex-direction: column;
		width: 78%;
		margin-top: 60rpx;
	}

	.user {
		display: flex;
		width: 100%;
		align-items: center;
	}

	.info-img {
		display: flex;
		justify-content: flex-start;
		width: 30%;
	}

	.info-content {
		margin-left: 60rpx;
	}

	.img {
		width: 140rpx;
		height: 140rpx;
	}

	.name {
		font-size: 46rpx;
	}

	.mobile {
		font-size: 32rpx;
		color: #cdcdcd;
		margin-top: 12rpx;
	}

	.menu {
		display: flex;
		flex-direction: column;
		margin-top: 30rpx;
	}

	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 40rpx;
	}

	.item-not-tap {
		font-size: 26rpx;
		color: rgb(139, 138, 138);
		padding-right: 10rpx;
	}

	.divider {
		width: 100%;
		height: 4rpx;
		background-color: #fec901;
		margin-top: 30rpx;
	}

	.item-label {
		font-size: 34rpx;
		padding-left: 6rpx;
	}

	.item-more {
		padding-right: 20rpx;
	}
	
	.contact-bg {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 100;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.feedback-bg {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 100;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.feedback-container {
		width: 78%;
		background-color: #fec901;
		border-radius: 28rpx;
		padding: 32rpx;
		z-index: 101;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.contact-container {
		height: 220rpx;
		width: 78%;
		background-color: #ffffff;
		border-radius: 24rpx;
		z-index: 101;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-shadow: 6rpx 4rpx 18rpx 0px rgba(67, 49, 10, 0.49);
	}
	
	.feedback-input-box {
		width: 88%;
		height: 570rpx;
		background-color: #ffffff;
		border-radius: 4rpx;
		padding: 20rpx;
	}
	
	.feedback-input {
		width: 100%;
		height: 100%;
	}
	
	.feedback-submit {
		width: 200rpx;
		height: 70rpx;
		background-color: #ffffff;
		font-size: 32rpx;
		margin-top: 60rpx;
		border-radius: 8rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		box-shadow: 2rpx 6rpx 18rpx 0px rgba(167, 167, 167, 0.71);
	}
	
	.contact-phone {
		font-size: 36rpx;
		margin-top: 30rpx;
	}
	
	.contact-phone-img {
		background-size: cover;
		width: 120rpx;
		height:120rpx;
		background-image: url();
	}
</style>
